﻿using AutoMapper;
using Frame.Core.Models;
using Frame.Core.Models.Dto;

namespace Frame.Core.AutoMapper
{
    public class CustomProfile : Profile
    {
        /// <summary>
        /// 配置构造函数，用来创建关系映射
        /// </summary>
        public CustomProfile()
        {
            //CreateMap<TSource, TDestination>()
            //.ForMember(d => d.DestName, opt => opt.MapFrom(s => s.Name))  //指定字段一一对应
            //.ForMember(d => d.Birthday, opt => opt.MapFrom(s => s.Birthday.ToString("yy-MM-dd HH:mm"))) //指定字段按指定的格式转化
            //.ForMember(d => d.Age, opt => opt.Condition(s => s.Age > 5))  //满足条件才赋值
            //.ForMember(d => d.A1, opt => opt.Ignore())  //忽略该字段，不给该字段赋值
            //.ForMember(d => d.A2, opt => opt.NullSubstitute("Default Value"))  //如果源字段值为空，则赋值为 Default Value
            //.ForMember(d => d.A3, opt => opt.MapFrom(s => s.Name + s.Age * 3 + s.Birthday.ToString("d")) //自己随意组合赋值

            ////排除映射
            //    Mapper.CreateMap<JsonRecord, DatabaseRecord>()
            //.Ignore(record => record.Field)
            //.Ignore(record => record.AnotherField)
            //.Ignore(record => record.Etc);

            //忽略目标DTo没有有属性
            //Mapper.CreateMap<SourceType, DestinationType>()
            //    .IgnoreAllNonExisting();

            CreateMap<Onlines, OnlinesDto>()
                .ForMember(d => d.UsersName, opt => opt.MapFrom(s => s.Users.Name))
                .ForMember(d => d.UsersChineseName, opt => opt.MapFrom(s => s.Users.ChineseName));

            CreateMap<Powers, PowersDto>()
                .ForMember(d => d.MenusName, opt => opt.MapFrom(s => s.Menus.Name));
        }

    }
}
